package com.ruoyi.system.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.system.domain.CheckVisit;
import com.ruoyi.system.domain.PrescriptionVisit;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.SysChecklist;
import com.ruoyi.system.service.ISysChecklistService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 检查订单Controller
 * 
 * @author ruoyi
 * @date 2024-06-29
 */
@RestController
@RequestMapping("/visit/checklist")
public class SysChecklistController extends BaseController
{
    @Autowired
    private ISysChecklistService sysChecklistService;

    /**
     * 查询检查订单列表
     */
    @PreAuthorize("@ss.hasPermi('visit:checklist:list')")
    @GetMapping("/list")
    public TableDataInfo list(SysChecklist sysChecklist)
    {
        startPage();
        List<SysChecklist> list = sysChecklistService.selectSysChecklistList(sysChecklist);
        return getDataTable(list);
    }

    /**
     * 导出检查订单列表
     */
    @PreAuthorize("@ss.hasPermi('visit:checklist:export')")
    @Log(title = "检查订单", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, SysChecklist sysChecklist)
    {
        List<SysChecklist> list = sysChecklistService.selectSysChecklistList(sysChecklist);
        ExcelUtil<SysChecklist> util = new ExcelUtil<SysChecklist>(SysChecklist.class);
        util.exportExcel(response, list, "检查订单数据");
    }

    /**
     * 获取检查订单详细信息
     */
    @PreAuthorize("@ss.hasPermi('visit:checklist:query')")
    @GetMapping(value = "/{checkId}")
    public AjaxResult getInfo(@PathVariable("checkId") Long checkId)
    {
        return success(sysChecklistService.selectSysChecklistByCheckId(checkId));
    }

    /**
     * 新增检查订单
     */
    @PreAuthorize("@ss.hasPermi('visit:checklist:add')")
    @Log(title = "检查订单", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody SysChecklist sysChecklist)
    {
        return toAjax(sysChecklistService.insertSysChecklist(sysChecklist));
    }

    /**
     * 修改检查订单
     */
    @PreAuthorize("@ss.hasPermi('visit:checklist:edit')")
    @Log(title = "检查订单", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody SysChecklist sysChecklist)
    {
        return toAjax(sysChecklistService.updateSysChecklist(sysChecklist));
    }

    /**
     * 删除检查订单
     */
    @PreAuthorize("@ss.hasPermi('visit:checklist:remove')")
    @Log(title = "检查订单", businessType = BusinessType.DELETE)
	@DeleteMapping("/{checkIds}")
    public AjaxResult remove(@PathVariable Long[] checkIds)
    {
        return toAjax(sysChecklistService.deleteSysChecklistByCheckIds(checkIds));
    }

    @PreAuthorize("@ss.hasPermi('visit:checklist:getPatientNameC')")
    @GetMapping(value = "/namelist/")
    public TableDataInfo getPatientNameC(CheckVisit checkVisit)
    {
        List<CheckVisit> list = sysChecklistService.selectPatientNameByVisitId(checkVisit);
        return getDataTable(list);
    }

    //导出带名称的表
    @PreAuthorize("@ss.hasPermi('visit:checklist:exportWithName')")
    @Log(title = "检查订单", businessType = BusinessType.EXPORT)
    @PostMapping("/exportWithName")
    public void exportWithName(HttpServletResponse response, CheckVisit checkVisit)
    {
        List<CheckVisit> list = sysChecklistService.selectPatientNameByVisitId(checkVisit);
        ExcelUtil<CheckVisit> util = new ExcelUtil<CheckVisit>(CheckVisit.class);
        util.exportExcel(response, list, "检查订单数据");
    }
}
